﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.复习八月份
{
    public class Solution41
    {
        public int FirstMissingPositive(int[] nums)
        {

            int len = nums.Length;
            for (int i = 0; i < len; i++)
            {


                if (nums[i] < 0)
                {
                    nums[i] = len + 1;//把负数转为正数，作为标记

                }
            }

            MyPrint(nums);
            for (int i = 0; i < len; i++)
            {

                int num = nums[i];
                Console.WriteLine(num);
                if (num > 0 )
                {
                    
                   
                }
                else//小于0说明标记过了
                {
                    num = -num;
                }

                
                if (num <= len)
            {

                    if (nums[num-1] > 0)
                    {
                        nums[num-1]=-nums[num-1];
                    }

            }

            }



            MyPrint(nums);
            for (int i = 0; i < len; i++)
            {


                if (nums[i] > 0)
                {
                    return i+1;

                }
            }

            return len+1;

        }

        private void MyPrint(int[] nums)
        {
            int len = nums.Length;
            for (int i = 0; i < len; i++)
            {

                Console.Write(nums[i]+",");
            }
            Console.WriteLine();
        }
    }

    class Program41
    {


        static void Main41(string[] args)
        {

            int[] nums = [1,2,0];
            Solution41 solution = new Solution41();

            int res= solution.FirstMissingPositive(nums);
            Console.WriteLine(res);
        }
    }
}
